package com.token.iot.bratterycharging.gateway.business;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.outstanding.framework.core.Logger;
import com.outstanding.framework.core.PendingException;
import com.outstanding.framework.log.LoggerFactory;
import com.token.iot.bratterycharging.gateway.IDGeneration;
import com.token.iot.bratterycharging.gateway.api.Constant;
import com.token.iot.bratterycharging.gateway.sender.AABSender;
import com.token.iot.bratterycharging.gateway.utils.ByteUtil;

import io.netty.channel.ChannelHandlerContext;

/**
 * 远程开关机
 * 
 * @author chenzhixuan
 *
 */
@Component("DKBDuplexProcessor")
public class DKBDuplexProcessor extends DuplexProcessor {

	

	@Override
	public String request(String imei, Map<String, String> params) throws PendingException {
		String val = params.get(Constant.FLAG);
		String c = "DKB";
		String sessionId = IDGeneration.createSeesionID();
		String command = null;
		if ("true".equalsIgnoreCase(val)) {
			command = c + sessionId + "/" + "0";
		} else {
			command = c + sessionId + "/" + "1";
		}
		loger.info("the send =" + new String(command));
		byte[] cc = ByteUtil.addFlag(command.getBytes());
		context.writeAndFlush(cc);
		return sessionId;
	}

	@Override
	public Object response(String response) throws PendingException {
		String val = response.substring(13);
		if("1".equals(val)) {
			return true;
		}else {
			return false;
		}
		
	}

	

}
